package social;

import java.util.*;
import java.sql.*;

import java.security.*;

import QuizPackage.QuizDBC;

import message.*;
public class SocialDBC {
	private String account = "ccs108htran1";
	private String password = "thakilae";
	private String server = "mysql-user-master.stanford.edu";
	private String database = "c_cs108_htran1";

	private Connection con;
	private Statement stmt;

	public SocialDBC () {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://" + server, account, password);
			stmt = con.createStatement();
			stmt.executeQuery("USE " + database);
		} catch (SQLException e) {
			//TODO HOW TO HANDLE EXCEPTIONS
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			//TODO HOW TO HANDLE EXCEPTIONS
			e.printStackTrace();
		}
	}

	public int addUser (String user, String password, String type) {
		String hash = hashPassword(password);

		if (userExists(user) == false) { //if user does not already exist
			try {
				String query = String.format("INSERT INTO userList VALUES(\"%s\", \"%s\", \"%s\");", user, hash, type);
				stmt = con.createStatement();
				stmt.executeUpdate(query);
			} catch (SQLException e) {
				//TODO catch exception
				e.printStackTrace();
				return -1;
			}
		} else {
			//user already exists
			return 1;
		}
		return 0;
	}

	public int removeUser (String user) {
		if (userExists(user)) {
			try {
				//1. friendList
				String friendQuery = String.format("DELETE FROM friendList WHERE friend1=\"%s\" OR friend2=\"%s\";", user, user);
				stmt.executeUpdate(friendQuery);
				//2. mailList
				String mailQuery = String.format("DELETE FROM mailList WHERE toUser=\"%s\" OR fromUser=\"%s\";", user, user);
				stmt.executeUpdate(mailQuery); 
				//3. userList
				String userQuery = String.format("DELETE FROM userList WHERE name=\"%s\";", user);
				stmt.executeUpdate(userQuery);
				// TODO 5. quizList
				// TODO 6. acheivementList
			} catch (SQLException e) {
				e.printStackTrace();
				return -1;
			}
		} else {
			System.err.println("User does not exist.");
			return -1;
		}

		return 0;
	}

	public boolean userExists (String user) {
		try {
			String query = String.format("SELECT name FROM userList WHERE name = \"%s\";", user);
			ResultSet rs = stmt.executeQuery(query);
			if (rs.next()) {
				return true; //user already exists
			} else {
				return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return true;
		}
	}

	public int numUser() {
		try {
			String query = String.format("SELECT * FROM userList;");
			ResultSet rs = stmt.executeQuery(query);
			rs.last();
			return rs.getRow();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	public String hashPassword (String password) {
		Cracker cracker = new Cracker(password);
		String hash = cracker.getHash();
		return hash;
	}

	public boolean checkPassword (String user, String password) {
		String hash = hashPassword(password);

		ResultSet rs;
		try {
			String query = String.format("SELECT name FROM userList WHERE name = \"%s\" AND password = \"%s\";", user, hash);
			rs = stmt.executeQuery(query);
			if (rs.next()) {
				return true;
			} else {
				return false;
			}
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return false;
		}
	}


	public int addFriend (String user1, String user2) {
		if (userExists(user1) && userExists(user2) && !alreadyFriends(user1, user2)) { //if both users exist and are not already friends
			try {
				String update1 = String.format("INSERT INTO friendList VALUES (\"%s\", \"%s\");", user1, user2);
				String update2 = String.format("INSERT INTO friendList VALUES (\"%s\", \"%s\");", user2, user1);
				stmt.executeUpdate(update1);
				stmt.executeUpdate(update2);
			}catch (SQLException e) {
				//TODO catch exception
				e.printStackTrace();
				return -1;
			}
		} else {
			//			//System.out.println("One of the users does not exist, or are already friends.");
			return 1;
		}
		return 0;
	}

	public int removeFriend (String user1, String user2) {
		//TODO UNIT TEST
		if (userExists(user1) && userExists(user2) && alreadyFriends(user1, user2)) {
			try {
				String update1 = String.format("DELETE FROM friendList WHERE friend1=\"%s\" AND friend2=\"%s\";", user1, user2);
				String update2 = String.format("DELETE FROM friendList WHERE friend1=\"%s\" AND friend2=\"%s\";", user2, user1);
				stmt.executeUpdate(update1);
				stmt.executeUpdate(update2);
				//				//System.out.println("friend removed");
			} catch (SQLException e) {
				e.printStackTrace();
				return -1;
			}
		} else {
			//System.out.println("One of the users does not exist or they are not friends.");
			return 1;
		}

		return 0;
	}

	public boolean alreadyFriends(String user1, String user2) {
		if (user1 == user2) {
			return true;
		}

		ResultSet rs;
		try {
			String query1 = String.format("SELECT friend1 FROM friendList WHERE friend1 = \"%s\" AND friend2 = \"%s\";", user1, user2);
			String query2 = String.format("SELECT friend1 FROM friendList WHERE friend1 = \"%s\" AND friend2 = \"%s\";", user2, user1);

			int size1;
			int size2;
			rs = stmt.executeQuery(query1);
			rs.last();
			size1 = rs.getRow();

			rs = stmt.executeQuery(query2);
			rs.last();
			size2 = rs.getRow();


			if (size1==0 && size2==0) {
				return false; //they are not already friends
			} else {
				return true; //they are already friends
			}
		} catch (SQLException e) {
			e.printStackTrace();

			return true;
		}
	}

	public ArrayList<String> getFriendList(String user) {
		ArrayList<String> friendList = new ArrayList<String>();

		ResultSet rs;
		try {
			rs = stmt.executeQuery(String.format("SELECT * FROM friendList WHERE friend1 = \"%s\";", user));

			while (rs.next()) {
				friendList.add(rs.getString("friend2"));
			}
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return null;
		}

		return friendList;
	}

	public int addMail (String toUser, String fromUser, String message, String type) {
		try {
			int id = getNextMailID();
			stmt.executeUpdate(String.format("INSERT INTO mailList VALUES (%d, \"%s\", \"%s\", \"%s\", \"%s\", %d);", id, toUser, fromUser, message, type, 0));
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return -1;
		}

		return 0;
	}



	public int addMail (AbstractMessage message) {
		try {
			String toUser = message.getToUser();
			String fromUser = message.getFromUser();
			String messageBody = message.getMessage();
			String type = message.getType();
			int id = getNextMailID();
			stmt.executeUpdate(String.format("INSERT INTO mailList VALUES (%d, \"%s\", \"%s\", \"%s\", \"%s\", %d);", id, toUser, fromUser, messageBody, type, 0));
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	public int addAnnouncement (String creator, String content) {
		try {
			int id = getNextAnnouncementID();
			stmt.executeUpdate(String.format("INSERT INTO announcementList VALUES (%d, \"%s\", \"%s\");", id, creator, content));
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	/*
	 * This function returns the next mail ID for a newly created message in the
	 * "master" mailList table.
	 */
	private int getNextMailID() {
		try {
			int id;
			String query = "SELECT id FROM mailList";

			ResultSet rs = stmt.executeQuery(query);
			if (!rs.next()) {
				return 1;
			} else {
				rs.last();
				id = Integer.parseInt((rs.getString("id")));
				id++;
				return id;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	/*
	 * This function returns the next mail ID for a newly created message in the
	 * "master" mailList table.
	 */
	private int getNextAnnouncementID() {
		try {
			int id;
			String query = "SELECT * FROM announcementList";

			ResultSet rs = stmt.executeQuery(query);
			if (!rs.next()) {
				return 1;
			} else {
				rs.last();
				id = Integer.parseInt((rs.getString("ID")));
				id = id + 1;
				return id;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	public ArrayList<AbstractMessage> getMail(String user) {
		ArrayList<AbstractMessage> mailList = new ArrayList<AbstractMessage>();

		ResultSet rs;
		try {
			rs = stmt.executeQuery(String.format("SELECT * FROM mailList WHERE toUser = \"%s\" OR fromUser = \"%s\";", user, user));

			while (rs.next()) {
				String toUser = rs.getString("toUser");
				String fromUser = rs.getString("fromUser");
				String message = rs.getString("message");
				String type = rs.getString("type");

				if (type.equals("note")) {
					Note note = new Note(toUser, fromUser, message);
					mailList.add(note);
				}
				if (type.equals("request")) {
					FriendRequest req = new FriendRequest(toUser, fromUser, message);
					mailList.add(req);
				}
				if (type.equals("challenge")) {
					Challenge chal = new Challenge(toUser, fromUser, message);
					mailList.add(chal);
				}
			}
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return null;
		}

		return mailList;
	}

	public ArrayList<String> getAnnouncement() {
		ArrayList<String> announcementList = new ArrayList<String>();

		ResultSet rs;
		try {
			rs = stmt.executeQuery("SELECT * FROM announcementList;");

			while (rs.next()) {
				String creator = rs.getString("CREATOR");
				String content = rs.getString("CONTENT");
				String announcement = "<b><u>"; 
				announcement = announcement.concat(String.format(" <a href=\"user-profile.jsp?profileName=%s\" > %s </a>", creator, creator));
				//announcement = announcement.concat(creator);
				announcement = announcement.concat(":</b></u> ");
				announcement = announcement.concat(content);
				announcementList.add(announcement);
			}
		} catch (SQLException e) {
			//TODO catch exception
			e.printStackTrace();
			return null;
		}

		return announcementList;
	}

	public void removeAnnouncement(String admin) {
		try {
			stmt.executeUpdate("DELETE FROM announcementList WHERE CREATOR = \""+admin+"\";");
		} catch (SQLException e) {}
	}

	public ArrayList<Integer> getMailIdList(String user) {
		ArrayList<Integer> mailIDs = new ArrayList<Integer>();

		ResultSet rs;
		try {
			String query = String.format("SELECT id FROM mailList WHERE toUser = \"%s\" OR fromUser = \"%s\" ORDER BY id;", user, user);
			//System.out.println(query);
			rs = stmt.executeQuery(query);
			while (rs.next()) {
				mailIDs.add(Integer.parseInt(rs.getString("id")));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}

		return mailIDs;
	}

	/**
	 * Returns an ArrayList of Integer objects that are the table ID's
	 * of the messages in the table that have not yet been read.
	 * @param user
	 * @return ArrayList<Integer> of unread mail IDs.
	 */
	public ArrayList<Integer> getUnreadMailIdList(String user) {
		ArrayList<Integer> mailIDs = new ArrayList<Integer>();

		ResultSet rs;
		try {
			String query = String.format("SELECT * FROM mailList WHERE toUser = \"%s\" AND viewed = 0;", user);
			rs = stmt.executeQuery(query);
			while (rs.next()) {
				mailIDs.add(Integer.parseInt(rs.getString("id")));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}

		return mailIDs;
	}

	public AbstractMessage getMailById(int id) {
		try {
			String query = String.format("SELECT * FROM mailList WHERE id = %d;", id);
			ResultSet rs = stmt.executeQuery(query);

			if (rs.next()) {
				String toUser = rs.getString("toUser");
				String fromUser = rs.getString("fromUser");
				String message = rs.getString("message");
				String type = rs.getString("type");

				if (type.equals("note")) {
					Note note = new Note(toUser, fromUser, message);
					return note;
				}
				if (type.equals("request")) {
					FriendRequest req = new FriendRequest(toUser, fromUser, message);
					return req;
				}
				if (type.equals("challenge")) {
					Challenge chal = new Challenge(toUser, fromUser, message);
					return chal;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}

		return null;
	}

	/**
	 * Function returns a boolean signifying whether or not the message has
	 * been read already.
	 * @param id
	 * @return boolean "viewed"
	 */
	public boolean checkMailViewed(int id) {
		try {
			String query = String.format("SELECT * FROM mailList WHERE id = %d;", id);
			ResultSet rs = stmt.executeQuery(query);

			if (rs.next()) {
				int viewed = Integer.parseInt(rs.getString("viewed"));

				if (viewed==0) {
					return false;
				} else {
					return true;
				}
			}

			return false;
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return false;
	}

	public boolean challengeExists(String toUser, String fromUser, int quizID) {
		try {
			String query = String.format("SELECT * FROM mailList WHERE toUser=\"%s\" AND fromUser=\"%s\" AND type=\"challenge\" AND message=\"%d\";", toUser, fromUser, quizID);
			ResultSet rs = stmt.executeQuery(query);

			if (rs.next()) {
				return true;
			} else {
				return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return false;
	}

	public int removeMail(String user1, String user2, String type) {
		try {
			String query1 = String.format("DELETE FROM mailList WHERE type=\"%s\" AND toUser=\"%s\" AND fromUser=\"%s\";", type, user1, user2);
			stmt.executeUpdate(query1);
			String query2 = String.format("DELETE FROM mailList WHERE type=\"%s\" AND toUser=\"%s\" AND fromUser=\"%s\";", type, user2, user1);
			stmt.executeUpdate(query2);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	public int removeMail(int id) {
		try {
			String update = String.format("DELETE FROM mailList WHERE id=%d;", id);
			stmt.executeUpdate(update);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	public int removeChallenges(int quizID) {
		try {
			String update = String.format("DELETE FROM mailList WHERE type=\"challenge\" AND message=\"%d\";", quizID);
			stmt.executeUpdate(update);
			stmt.executeUpdate("DELETE FROM mailList WHERE message LIKE \"<a href=StartQuiz.jsp?quizid="+quizID+">% was flagged as inappropriate.</a>\";");
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		
		return 0;
	}
	
	public int reportQuiz(String username, int quizID, QuizDBC qdb) {
		try {
			String query = "SELECT * FROM userList WHERE type=\"admin\";";
			ResultSet rs = stmt.executeQuery(query);
			
			ArrayList<String> adminList = new ArrayList<String>();
			while (rs.next()) {
				adminList.add(rs.getString("name"));
			}
			
			for (int i=0; i<adminList.size(); i++) {
				String quizName = qdb.getStringByID(quizID, "name");
				String msg = String.format("<a href=StartQuiz.jsp?quizid=%d>%s was flagged as inappropriate.</a>", quizID, quizName);
				addMail(adminList.get(i), username, msg, "note");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		
		return 0;
	}
	
	public int getNumUnreadMail(String user) {
		try {
			String query = String.format("SELECT * FROM mailList WHERE viewed = 0 AND toUser=\""+user+"\";");
			ResultSet rs = stmt.executeQuery(query);
			rs.last();
			////System.out.println("num = " + rs.getRow());
			return rs.getRow();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;

	}

	public int setMailViewed (int id) {
		try {
			String update = String.format("UPDATE mailList SET viewed = 1 WHERE id = %d;", id);
			int rs = stmt.executeUpdate(update);

			return rs;
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	public boolean friendRequestSent(String toUser, String fromUser) {
		try {
			String query = String.format("SELECT * FROM mailList WHERE toUser = \"%s\" AND fromUser = \"%s\"", toUser, fromUser);
			ResultSet rs = stmt.executeQuery(query);

			if (rs.next()) {
				return true;
			} else {
				return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return false;
	}

	public int addQuizCreated(String username, int quizID) {
		try {
			String update = String.format("INSERT INTO createdHistoryList VALUES(\"%s\", %d);", username, quizID);
			stmt.executeUpdate(update);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	public int addQuizTaken(String username, int quizID) {
		try {
			String update = String.format("INSERT INTO takenHistoryList VALUES(\"%s\", %d);", username, quizID);
			stmt.executeUpdate(update);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}

	public ArrayList<Integer> getQuizzesCreated (String username) {
		ArrayList<Integer> quizzesCreated = new ArrayList<Integer>();
		try {
			String query = String.format("SELECT * FROM createdHistoryList WHERE username=%s", username);
			ResultSet rs = stmt.executeQuery(query);

			while (rs.next()) {
				quizzesCreated.add(Integer.parseInt(rs.getString("quizID")));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return quizzesCreated;
	}

	public ArrayList<Integer> getQuizzesTaken (String username) {
		ArrayList<Integer> quizzesTaken = new ArrayList<Integer>();
		try {
			String query = String.format("SELECT * FROM takenHistoryList WHERE username=%s", username);
			ResultSet rs = stmt.executeQuery(query);

			while (rs.next()) {
				quizzesTaken.add(Integer.parseInt(rs.getString("quizID")));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return quizzesTaken;
	}

	public ArrayList<String> searchUsers (String username) {
		//TODO UNIT TEST
		ArrayList<String> searchResults = new ArrayList<String>();
		//System.out.println("username:" + username);
		ResultSet rs;
		try {
			String query = String.format("SELECT * FROM userList WHERE name LIKE \"%s%s%s\";", "%", username, "%");
			//System.out.println("search query:" + query);
			rs = stmt.executeQuery(query);

			while (rs.next()) {
				searchResults.add(rs.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}

		return searchResults;
	}

	//Check if an user is an admin or not
	public boolean checkAdmin(String userName) {
		try {
			ResultSet rs;
			rs = stmt.executeQuery("SELECT type FROM userList WHERE name = \""+userName+"\";");

			while (rs.next()) {
				if (rs.getString("type").equals("admin")) {
					return true;
				} else return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return false;
	}

	//Promote an user to admin
	public void promoteAdmin(String userName) {
		try {
			stmt.executeUpdate("UPDATE userList SET type = \"admin\"" +
					"WHERE name = \""+userName+"\";");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void removeAdmin(String userName) {
		try {
			stmt.executeUpdate("UPDATE userList SET type = \"user\"" +
					"WHERE name = \""+userName+"\";");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public int updateTakenAcheivements(String username, int quizID, boolean practiceMode, QuizDBC qdb) {
		//Quiz Machine
		try {
			String query = String.format("SELECT * FROM acheivementList WHERE username=\"%s\" AND acheivement=\"QuizMachine\";", username);
			ResultSet rs = stmt.executeQuery(query);
			if (!rs.next()) {
				rs = qdb.getResultSet(username);

				int count = 0;
				HashSet<Integer> quizSet = new HashSet<Integer>();
				while (rs.next()) {
					if (count==10) break;
					int id = Integer.parseInt(rs.getString("quizid"));

					if (!quizSet.contains(id)) {
						count++;
						quizSet.add(id);
					}
				}

				if (count >= 10) {
					String update = String.format("INSERT INTO acheivementList VALUES(\"%s\", \"QuizMachine\");", username);
					stmt.executeUpdate(update);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		//Greatest
		try {
			String query = String.format("SELECT * FROM acheivementList WHERE username=\"%s\" AND acheivement=\"I am the Greatest\";", username);
			ResultSet rs = stmt.executeQuery(query);
			if (!rs.next()) {
				//query = String.format("SELECT * FROM results WHERE quizid=%d ORDER BY score DESC;", quizID);
				rs = qdb.getTopPerformers(quizID);

				int place = 0;
				while (rs.next()) {
					if (place==10) break;

					String user = rs.getString("userID");
					if (username.equals(user)) {
						String update = String.format("INSERT INTO acheivementList VALUES(\"username\", \"I am the Greatest\");", username);
						stmt.executeUpdate(update);
						break;
					}
					place++;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		//Practice Mode
		if (practiceMode) {
			try {
				String query = String.format("SELECT * FROM acheivementList WHERE username=\"%s\" AND acheivement=\"Practice Makes Perfect\";", username);
				ResultSet rs = stmt.executeQuery(query);

				if (!rs.next()) {
					String update = String.format("INSERT INTO acheivementList VALUES(\"username\", \"Practice Makes Perfect\");", username);
					stmt.executeUpdate(update);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return 0;
	}

	public int updateWritenAcheivements(String username, QuizDBC qdb) {
		//Quiz Created Acheivements
		HashSet<String> writtenAcheivements = new HashSet<String>();
		ArrayList<Integer> quizList = qdb.getQuizListByCreator(username);

		try {
			String query = String.format("SELECT * FROM acheivementList WHERE username=\"%s\";", username);
			ResultSet rs = stmt.executeQuery(query);

			while (rs.next()) {
				String acheivement = rs.getString("acheivement");
				writtenAcheivements.add(acheivement);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}

		try {
			//System.out.println("size:" + quizList.size());
			//System.out.println("updating acheivements");
			if (quizList.size() > 0 && !writtenAcheivements.contains("Amateur Author")) {
				String update = String.format("INSERT INTO acheivementList VALUES(\"%s\", \"Amateur Author\");", username);
				stmt.executeUpdate(update);
			}

			if (quizList.size() >= 5 && !writtenAcheivements.contains("Prolific Author")) {
				String update = String.format("INSERT INTO acheivementList VALUES(\"%s\", \"Prolific Author\");", username);
				stmt.executeUpdate(update);
			}

			if (quizList.size() >= 10 && !writtenAcheivements.contains("Prodigious Author")) {
				String update = String.format("INSERT INTO acheivementList VALUES(\"%s\", \"Prodigious Author\");", username);
				stmt.executeUpdate(update);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		return 0;
	}
	
	public ArrayList<String> getAcheivementList(String username) {
		ArrayList<String> acheivementList = new ArrayList<String>();
		try {
			String query = String.format("SELECT * FROM acheivementList WHERE username=\"%s\";", username);
			ResultSet rs = stmt.executeQuery(query);
			
			while (rs.next()) {
				String acheivement = rs.getString("acheivement");
				acheivementList.add(acheivement);
			}
		} catch(SQLException e) {
			e.printStackTrace();
		}
		
		return acheivementList;
	}
	
	public int removeAcheivements(String username) {
		try {
			String update = String.format("DELETE FROM acheivementList WHERE username=\"%s\";", username);
			stmt.executeUpdate(update);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		
		return 0;
	}

	public void clearDatabase () {
		try {
			stmt.executeQuery(String.format("TRUNCATE TABLE %s;", "userList"));
			stmt.executeQuery(String.format("TRUNCATE TABLE %s;", "mailList"));
			stmt.executeQuery(String.format("TRUNCATE TABLE %s;", "friendList"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
